package com.example.property
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.common.base.BaseActivity
import com.example.path.RouterPath
import com.example.property.databinding.ActivityPropertyBinding
import com.example.property.framgnet.AddMaintenanceFragment
import com.example.property.framgnet.CarApplyFragment
import com.example.property.framgnet.MaintenanceFragment
import com.example.property.framgnet.MineApplyFragment
import com.example.property.framgnet.PatrolFragment
import com.example.property.framgnet.WelcomeFragment
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterPath.PATH_PROPERTY)
@AndroidEntryPoint
class PropertyActivity : BaseActivity<ActivityPropertyBinding>() {

    @Autowired
    @JvmField
    var moduleType :String="1"

    override fun getLayoutId(): Int =R.layout.activity_property
    override fun initViews() {
        ARouter.getInstance().inject(this)
        initFragment()
        mDataBinding.includedPageTitle.ivBack.setOnClickListener {
            finish()
        }
    }

    /*
     *初始化fragment
     */
    private fun initFragment() {
        when(moduleType){
            "1"->commitFragment(CarApplyFragment.newInstance(),"车位申请")
            "2"->commitFragment(MineApplyFragment.newInstance(),"我的申请")
            "3"->commitFragment(WelcomeFragment.newInstance(),"来访预约")
            "4"->commitFragment(PatrolFragment.newInstance(),"巡更管理")
            "5"->commitFragment(MaintenanceFragment.newInstance(),"维修管理")
            "6"->commitFragment(AddMaintenanceFragment.newInstance(),"添加微修")
        }
    }

    /**
     * 提交Fragment嵌套Activity
     * */
    private fun commitFragment(targetFragment:Fragment,fragmentTag :String){
        //获取FragmentManger
        var fragmentManger =supportFragmentManager
        val beginTransaction = fragmentManger.beginTransaction()
        beginTransaction.replace(R.id.fragment,targetFragment,fragmentTag)
        beginTransaction.commit()
        mDataBinding.includedPageTitle.tvTitle.text=fragmentTag
    }





}